package com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.childfragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;

import com.example.qingyiapp.R;
import com.example.qingyiapp.service.entify.FindChoicenessOneBean;
import com.example.qingyiapp.service.entify.FindChoicenessTwoBean;
import com.example.qingyiapp.service.entify.FindSynamicBean;
import com.example.qingyiapp.service.entify.FindTJBean;
import com.example.qingyiapp.service.entify.FindWaitYouBean;
import com.example.qingyiapp.service.presenter.PersenterMannaer;
import com.example.qingyiapp.service.view.IFindView;
import com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.QuestionActivity;
import com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.adapter.FindSquareWaityouRecyclerAdapter;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Creadted by Met·Wang on 2019/9/21 16:54
 * Describe: NullPointerException Write
 */
public class waiyou_fragment extends Fragment implements IFindView {


    @BindView(R.id.find_squre_fragment)
    XRecyclerView findSqureFragment;
    Unbinder unbinder;


    PersenterMannaer iRequestPersenter;


    ArrayList<FindWaitYouBean.DataBean> list;
    FindSquareWaityouRecyclerAdapter  adapter;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {


        final View inflate = inflater.inflate(R.layout.fragment_find_square_waityou, container, false);
        unbinder = ButterKnife.bind(this, inflate);



        iRequestPersenter=new PersenterMannaer(getContext(),"http://www.iqingyi.com/");
        iRequestPersenter.onCreate();
        iRequestPersenter.attchview2(this);
        iRequestPersenter.getFindWaitYouBean();


        list=new ArrayList<>();
        adapter=new FindSquareWaityouRecyclerAdapter(list,getContext());
        LinearLayoutManager manager=new LinearLayoutManager(getContext());
        findSqureFragment.setLayoutManager(manager);
        findSqureFragment.setAdapter(adapter);


        adapter.setOnClick(new FindSquareWaityouRecyclerAdapter.OnItemClick() {
            @Override
            public void onClick(int i) {
                String qa_id = list.get(i).getQa_id();
                Intent intent = new Intent(getActivity(), QuestionActivity.class);
                intent.putExtra("qa_id",qa_id);
                startActivity(intent);
            }
        });


        return inflate;
    }

    @Override
    public void getjsonstring(FindTJBean s) {

    }

    @Override
    public void getChoicenessOneBean(FindChoicenessOneBean bean) {

    }

    @Override
    public void getChoicenessTwoBean(FindChoicenessTwoBean bean) {

    }

    @Override
    public void getFindWaitYou(FindWaitYouBean bean) {
        List<FindWaitYouBean.DataBean> data = bean.getData();

        for (int i = 0; i < data.size(); i++) {
            list.add(data.get(i));
        }

        adapter.notifyDataSetChanged();
    }

    @Override
    public void getFindSynamic(FindSynamicBean bean) {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
